# -*- coding: utf-8 -*-

import sys
import datetime


# pip install line_profiler
import line_profiler
from py_file import write_aline

# @profile
def logfile(line):
    """
    报错：基础开发环境不识别装饰器@profile
    命令：kernprof -l -v py_line_profiler.py
    生成：py_line_profiler.py.lprof
    """

    # 以追加模式按行将文本写入文件
    with open("log.log", mode='a+') as file:
        file.write(line + "\n")
        pass


def py_line_profiler():

    # 方法一
    lp = line_profiler.LineProfiler(write_aline)
    lp.enable()
    write_aline("logs/1.log", datetime.datetime.now().strftime("%Y-%m-%d"))
    lp.disable()
    lp.print_stats(sys.stdout)

    # 方法二
    # lp = line_profiler.LineProfiler()
    # fc = lp(write_aline)
    # fc("logs/1.log", datetime.datetime.now().strftime("%Y-%m-%d"))
    # lp.print_stats(sys.stdout)

    pass




if __name__ == '__main__':

    # logfile(datetime.datetime.now().strftime("%Y-%m-%d"))

    py_line_profiler()

    pass
